package org.nt4b.schemadoc.webgui.service;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.nt4b.schemadoc.core.dao.SchemaDocDAO;
import org.nt4b.schemadoc.core.dom.SchemaComments;
import org.nt4b.schemadoc.core.dom.Table;
import org.springframework.transaction.annotation.Transactional;


@Transactional
public class TransactionalCommentsServiceImpl implements Serializable, TransactionalCommentsService {
    private static final long serialVersionUID = 6881180288607970082L;
    
    protected Logger logger = Logger.getLogger(TransactionalCommentsServiceImpl.class);
    
    @Override
    public List<Table> loadSchemaComments(final SchemaDocDAO dao, final String schemaName) {
        final List<Table> tables = dao.getSchemaComments(schemaName);
        return tables;
    }
    
    @Override
    public List<Table> loadTableComments(final SchemaDocDAO dao, final String schemaName) {
        final List<Table> tables = dao.getTableComments(schemaName);
        return tables;
    }
    
    @Override
    public Table loadColumnComments(final SchemaDocDAO dao, final String schemaName, final String tableName) {
        final Table table = dao.getTableComments(schemaName, tableName);
        return table;
    }
    
    @Override
    public void saveSchemaComments(final SchemaDocDAO dao, final SchemaComments schemaComments) {
        final List<Table> tables = schemaComments.getTables();
        dao.save(tables);
    }
    
    @Override
    public void saveTableComments(final SchemaDocDAO dao, final List<Table> tables) {
        dao.save(tables);
    }
    
}
